﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _01_Button按钮
{
    public partial class Form1 : Form
    {
        //点的状态
        PointState pointState = PointState.None;

        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show("罗老师！下午好！");
        }
        /// <summary>
        /// 绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            this.button3.Click += new System.EventHandler(this.button3_Click);
            this.button4.Click += new System.EventHandler(this.button4_Click);
            this.button5.Click += new System.EventHandler(this.button5_Click);

        }
        /// <summary>
        /// 解绑事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.button3.Click -= new System.EventHandler(this.button3_Click);
            this.button4.Click -= new System.EventHandler(this.button4_Click);
            this.button5.Click -= new System.EventHandler(this.button5_Click);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show("嘉嘉老师！下午好！");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show("蔡老师！下午好！");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.button6.Visible = false;
            this.button7.Visible = true;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            this.button7.Visible = false;
            this.button8.Visible = true;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            this.button8.Visible = false;
            this.button9.Visible = true;
        }

        private void button9_Click(object sender, EventArgs e)
        {
            this.button9.Visible = false;
            this.button10.Visible = true;
        }

        private void button10_Click(object sender, EventArgs e)
        {
            this.button10.Visible = false;
            this.button6.Visible = true;
        }

        private void button11_Click(object sender, EventArgs e)
        {
            this.button11.Enabled = false;
            this.button12.Enabled = true;
        }

        private void button12_Click(object sender, EventArgs e)
        {
            this.button12.Enabled = false;
            this.button13.Enabled = true;
        }

        private void button13_Click(object sender, EventArgs e)
        {
            this.button13.Enabled = false;
            this.button14.Enabled = true;
        }

        private void button14_Click(object sender, EventArgs e)
        {
            this.button14.Enabled = false;
            this.button15.Enabled = true;
        }

        private void button15_Click(object sender, EventArgs e)
        {
            this.button15.Enabled = false;
            this.button11.Enabled = true;
        }

        private void button16_MouseEnter(object sender, EventArgs e)
        {
            this.button16.BackColor = Color.DarkOrange;
        }

        private void button16_MouseLeave(object sender, EventArgs e)
        {
            this.button16.BackColor = Color.SeaGreen;
        }
        /// <summary>
        /// 点击动作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button16_Click(object sender, EventArgs e)
        {
            if (this.button16.Text.Trim() == "启 动")
            {
                this.button16.Text = "  停 止";
                this.button16.BackColor = Color.Red;
                this.button16.Image = global::_01_Button按钮.Properties.Resources.停止;
            }
            else
            {
                this.button16.Text = "  启 动";
                this.button16.BackColor = Color.SeaGreen;
                this.button16.Image = global::_01_Button按钮.Properties.Resources.启动;
            }

        }

        private void Form1_Shown(object sender, EventArgs e)
        {

        }

        private void button18_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void button18_MouseDown(object sender, MouseEventArgs e)
        {
            pointState = PointState.UP;
        }

        private void button18_MouseUp(object sender, MouseEventArgs e)
        {
            pointState = PointState.None;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            switch (pointState)
            {
                case PointState.None:
                    break;
                case PointState.UP:
                    this.button22.Location = new Point(this.button22.Location.X, this.button22.Location.Y - 1);
                    break;
                case PointState.DOWN:
                    this.button22.Location = new Point(this.button22.Location.X, this.button22.Location.Y + 1);
                    break;
                case PointState.LEFT:
                    this.button22.Location = new Point(this.button22.Location.X-1, this.button22.Location.Y );
                    break;
                case PointState.RIGHT:
                    this.button22.Location = new Point(this.button22.Location.X + 1, this.button22.Location.Y);
                    break;
            }
        }

        private void button21_MouseDown(object sender, MouseEventArgs e)
        {
            pointState = PointState.RIGHT;
        }

        private void button20_MouseDown(object sender, MouseEventArgs e)
        {
            pointState = PointState.LEFT;
        }

        private void button19_MouseDown(object sender, MouseEventArgs e)
        {
            pointState = PointState.DOWN;
        }
        /// <summary>
        /// 鼠标按下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
             if (e.KeyCode == Keys.Up)
            {
                pointState = PointState.UP;
            }
            else if (e.KeyCode == Keys.Down)
            {
                pointState = PointState.DOWN;
            }
            else if (e.KeyCode == Keys.Left)
            {
                pointState = PointState.LEFT;
            }
            else if (e.KeyCode == Keys.Right)
            {
                pointState = PointState.RIGHT;
            }
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode== Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
            {
                    pointState = PointState.None;
            }
        }
    }
}
